#include <iostream>
#include <stdio.h>

class IBase 
{
	public:
		IBase() {
			member = 1;
			printf("IBase()\r\n");
		}

		virtual void fun1() = 0;
		virtual void fun2() = 0;

	private:
		int member;
};

class CDerived : public IBase
{
	public:
		CDerived() {
			printf("CDerived()\r\n");
		}

		virtual void fun1() {
			printf("CDerived:fun1.\n");
		}

		virtual void fun2() {
			printf("CDerived:fun2.\n");
		}
};

int main()
{
	IBase *pBase = new CDerived();

	pBase->fun1();

	delete pBase;

	return 0;
}

/*
	纯虚函数被继承，了类必须实现父类的 virtual 函数，不然编译报错。
 */

#if 0

/*
 * intel
 */
00000000000011e9 <main>:
    11e9:	f3 0f 1e fa          	endbr64 
    11ed:	55                   	push   %rbp
    11ee:	48 89 e5             	mov    %rsp,%rbp
    11f1:	41 54                	push   %r12
    11f3:	53                   	push   %rbx
    11f4:	48 83 ec 10          	sub    $0x10,%rsp
    11f8:	bf 10 00 00 00       	mov    $0x10,%edi	// edi=0x10
    11fd:	e8 ae fe ff ff       	callq  10b0 <_Znwm@plt>	// new(0x10)
    1202:	48 89 c3             	mov    %rax,%rbx	// rbx=rax
    1205:	48 89 df             	mov    %rbx,%rdi	// rdi=rbx
    1208:	e8 fb 00 00 00       	callq  1308 <_ZN8CDerivedC1Ev>
    120d:	48 89 5d e8          	mov    %rbx,-0x18(%rbp)	// (rbp-0x18)=rbx
    1211:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=(rbp-0x18)
    1215:	48 8b 00             	mov    (%rax),%rax	// rax=(rax)
    1218:	48 8b 10             	mov    (%rax),%rdx	// rdx=(rax)
    121b:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=(rbp-0x18)
    121f:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    1222:	ff d2                	callq  *%rdx		// rdx(rdi)
    1224:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=(rbp-0x18)
    1228:	48 85 c0             	test   %rax,%rax	// rax&rax
    122b:	74 0d                	je     123a <main+0x51>	// == jump
    122d:	be 10 00 00 00       	mov    $0x10,%esi	// esi=0x10
    1232:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    1235:	e8 86 fe ff ff       	callq  10c0 <_ZdlPvm@plt>
    123a:	b8 00 00 00 00       	mov    $0x0,%eax	// eax=0
    123f:	eb 1f                	jmp    1260 <main+0x77>
    1241:	f3 0f 1e fa          	endbr64 
    1245:	49 89 c4             	mov    %rax,%r12	// r12=rax
    1248:	be 10 00 00 00       	mov    $0x10,%esi	// esi=0x10
    124d:	48 89 df             	mov    %rbx,%rdi	// rdi=rbx
    1250:	e8 6b fe ff ff       	callq  10c0 <_ZdlPvm@plt>
    1255:	4c 89 e0             	mov    %r12,%rax	// rax=r12
    1258:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    125b:	e8 90 fe ff ff       	callq  10f0 <_Unwind_Resume@plt>
    1260:	48 83 c4 10          	add    $0x10,%rsp	// rsp+=0x10
    1264:	5b                   	pop    %rbx	
    1265:	41 5c                	pop    %r12
    1267:	5d                   	pop    %rbp
    1268:	c3                   	retq   

00000000000012d0 <_ZN5IBaseC1Ev>:
    12d0:	f3 0f 1e fa          	endbr64 
    12d4:	55                   	push   %rbp
    12d5:	48 89 e5             	mov    %rsp,%rbp
    12d8:	48 83 ec 10          	sub    $0x10,%rsp
    12dc:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)	// (rbp-0x8)=rdi
    12e0:	48 8d 15 59 2a 00 00 	lea    0x2a59(%rip),%rdx        # 3d40 <__cxa_pure_virtual@CXXABI_1.3>
    12e7:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=(rbp-0x8)
    12eb:	48 89 10             	mov    %rdx,(%rax)	// (rax)=rdx
    12ee:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=(rbp-0x8)
    12f2:	c7 40 08 01 00 00 00 	movl   $0x1,0x8(%rax)	// (rax+0x8)=0x1
    12f9:	48 8d 3d 05 0d 00 00 	lea    0xd05(%rip),%rdi        # 2005 <_ZStL19piecewise_construct+0x1>
    1300:	e8 db fd ff ff       	callq  10e0 <puts@plt>
    1305:	90                   	nop
    1306:	c9                   	leaveq 
    1307:	c3                   	retq   

0000000000001308 <_ZN8CDerivedC1Ev>:
    1308:	f3 0f 1e fa          	endbr64 
    130c:	55                   	push   %rbp
    130d:	48 89 e5             	mov    %rsp,%rbp
    1310:	48 83 ec 10          	sub    $0x10,%rsp
    1314:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)	// (rbp-0x8)=rdi
    1318:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=(rbp-0x8)
    131c:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    131f:	e8 ac ff ff ff       	callq  12d0 <_ZN5IBaseC1Ev>
    1324:	48 8d 15 f5 29 00 00 	lea    0x29f5(%rip),%rdx        # 3d20 <_ZTV8CDerived+0x10>
    132b:	48 8b 45 f8          	mov    -0x8(%rbp),%rax	// rax=(rbp-0x8)
    132f:	48 89 10             	mov    %rdx,(%rax)	// (rax)=rdx
    1332:	48 8d 3d d5 0c 00 00 	lea    0xcd5(%rip),%rdi        # 200e <_ZStL19piecewise_construct+0xa>
    1339:	e8 a2 fd ff ff       	callq  10e0 <puts@plt>
    133e:	90                   	nop
    133f:	c9                   	leaveq 
    1340:	c3                   	retq   
    1341:	90                   	nop

0000000000001342 <_ZN8CDerived4fun1Ev>:
    1342:	f3 0f 1e fa          	endbr64 
    1346:	55                   	push   %rbp
    1347:	48 89 e5             	mov    %rsp,%rbp
    134a:	48 83 ec 10          	sub    $0x10,%rsp
    134e:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)	// (rbp-0x8)=rdi
    1352:	48 8d 3d c1 0c 00 00 	lea    0xcc1(%rip),%rdi        # 201a <_ZStL19piecewise_construct+0x16>
    1359:	e8 82 fd ff ff       	callq  10e0 <puts@plt>
    135e:	90                   	nop
    135f:	c9                   	leaveq 
    1360:	c3                   	retq   
    1361:	90                   	nop

0000000000001362 <_ZN8CDerived4fun2Ev>:
    1362:	f3 0f 1e fa          	endbr64 
    1366:	55                   	push   %rbp
    1367:	48 89 e5             	mov    %rsp,%rbp
    136a:	48 83 ec 10          	sub    $0x10,%rsp
    136e:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)	// (rbp-0x8)=rdi
    1372:	48 8d 3d b0 0c 00 00 	lea    0xcb0(%rip),%rdi        # 2029 <_ZStL19piecewise_construct+0x25>
    1379:	e8 62 fd ff ff       	callq  10e0 <puts@plt>
    137e:	90                   	nop
    137f:	c9                   	leaveq 
    1380:	c3                   	retq   
    1381:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    1388:	00 00 00 
    138b:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)

/*
 * arm
 */
0000000000400a2c <main>:
  400a2c:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  400a30:	910003fd 	mov	x29, sp
  400a34:	a90153f3 	stp	x19, x20, [sp, #16]
  400a38:	d2800200 	mov	x0, #0x10                  	// #16
  400a3c:	97ffffb5 	bl	400910 <_Znwm@plt>	// new(0x10)
  400a40:	aa0003f3 	mov	x19, x0			// x19=x0
  400a44:	aa1303e0 	mov	x0, x19			// x0=x19
  400a48:	94000044 	bl	400b58 <_ZN8CDerivedC1Ev>
  400a4c:	f90017b3 	str	x19, [x29, #40]	// [x29+40]=x19
  400a50:	f94017a0 	ldr	x0, [x29, #40]	// x0=[x29+40]
  400a54:	f9400000 	ldr	x0, [x0]	// x0=[x0]
  400a58:	f9400001 	ldr	x1, [x0]	// x1=[x0]
  400a5c:	f94017a0 	ldr	x0, [x29, #40]	// x0=[x29+40]
  400a60:	d63f0020 	blr	x1		// x1()
  400a64:	d2800201 	mov	x1, #0x10                  	// #16
  400a68:	f94017a0 	ldr	x0, [x29, #40]	// x0=[x29+40]
  400a6c:	97ffff89 	bl	400890 <_ZdlPvm@plt>
  400a70:	52800000 	mov	w0, #0x0                   	// #0
  400a74:	14000007 	b	400a90 <main+0x64>
  400a78:	aa0003f4 	mov	x20, x0		// x20=x0
  400a7c:	d2800201 	mov	x1, #0x10                  	// #16
  400a80:	aa1303e0 	mov	x0, x19		// x0=x19
  400a84:	97ffff83 	bl	400890 <_ZdlPvm@plt>
  400a88:	aa1403e0 	mov	x0, x20		// x0=x20
  400a8c:	97ffffa5 	bl	400920 <_Unwind_Resume@plt>
  400a90:	a94153f3 	ldp	x19, x20, [sp, #16]
  400a94:	a8c37bfd 	ldp	x29, x30, [sp], #48
  400a98:	d65f03c0 	ret

0000000000400b18 <_ZN5IBaseC1Ev>:
  400b18:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400b1c:	910003fd 	mov	x29, sp
  400b20:	f9000fa0 	str	x0, [x29, #24]	// [x29+24]=x0
  400b24:	90000000 	adrp	x0, 400000 <_init-0x830>
  400b28:	91342001 	add	x1, x0, #0xd08
  400b2c:	f9400fa0 	ldr	x0, [x29, #24]	// x0=[x29+24]
  400b30:	f9000001 	str	x1, [x0]	// [x0]=x0
  400b34:	f9400fa0 	ldr	x0, [x29, #24]	// x0=[x29+24]
  400b38:	52800021 	mov	w1, #0x1                   	// #1
  400b3c:	b9000801 	str	w1, [x0, #8]	// [x0+8]=w1
  400b40:	90000000 	adrp	x0, 400000 <_init-0x830>
  400b44:	91326000 	add	x0, x0, #0xc98
  400b48:	97ffff6a 	bl	4008f0 <puts@plt>
  400b4c:	d503201f 	nop
  400b50:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400b54:	d65f03c0 	ret

0000000000400b58 <_ZN8CDerivedC1Ev>:
  400b58:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400b5c:	910003fd 	mov	x29, sp
  400b60:	f9000fa0 	str	x0, [x29, #24]	// [x29+24]=x0
  400b64:	f9400fa0 	ldr	x0, [x29, #24]	// x0=[x29+24]
  400b68:	97ffffec 	bl	400b18 <_ZN5IBaseC1Ev>
  400b6c:	90000000 	adrp	x0, 400000 <_init-0x830>
  400b70:	9133a001 	add	x1, x0, #0xce8
  400b74:	f9400fa0 	ldr	x0, [x29, #24]	// x0=[x29+24]
  400b78:	f9000001 	str	x1, [x0]	// [x0]=x1
  400b7c:	90000000 	adrp	x0, 400000 <_init-0x830>
  400b80:	9132a000 	add	x0, x0, #0xca8
  400b84:	97ffff5b 	bl	4008f0 <puts@plt>
  400b88:	d503201f 	nop
  400b8c:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400b90:	d65f03c0 	ret

0000000000400b94 <_ZN8CDerived4fun1Ev>:
  400b94:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400b98:	910003fd 	mov	x29, sp
  400b9c:	f9000fa0 	str	x0, [x29, #24]	// [x29+24]=x0
  400ba0:	90000000 	adrp	x0, 400000 <_init-0x830>
  400ba4:	9132e000 	add	x0, x0, #0xcb8
  400ba8:	97ffff52 	bl	4008f0 <puts@plt>
  400bac:	d503201f 	nop
  400bb0:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400bb4:	d65f03c0 	ret

0000000000400bb8 <_ZN8CDerived4fun2Ev>:
  400bb8:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400bbc:	910003fd 	mov	x29, sp
  400bc0:	f9000fa0 	str	x0, [x29, #24]	// [x29+24]=x0
  400bc4:	90000000 	adrp	x0, 400000 <_init-0x830>
  400bc8:	91332000 	add	x0, x0, #0xcc8
  400bcc:	97ffff49 	bl	4008f0 <puts@plt>
  400bd0:	d503201f 	nop
  400bd4:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400bd8:	d65f03c0 	ret
  400bdc:	00000000 	.inst	0x00000000 ; undefined

#endif
